﻿CREATE PROCEDURE [maint].[IsLogBackupRequired]
@DbName [sysname], @Required BIT=0 OUTPUT, @OutputDiagnostics BIT=0
AS
BEGIN
	IF(@OutputDiagnostics = 1)
		BEGIN
			PRINT OBJECT_NAME(@@PROCID)
			PRINT N'	@DbName = N''' + ISNULL(@DbName,N'NULL') + ''''
		END

	DECLARE @IsLogShipped bit = 0;
	IF EXISTS(
		SELECT * FROM [msdb].[dbo].[log_shipping_primary_databases]
		WHERE ([primary_database] = @DbName)
	)
		SET @IsLogShipped = 1;

	IF (@IsLogShipped = 1)
	OR (@DbName IN (N'master',N'model','tempdb'))
	OR (DATABASEPROPERTYEX(@DbName,'Recovery') = 'SIMPLE')
		SET @Required = 0
	ELSE	
		SET @Required = 1

	RETURN(0)
END